<?php

namespace App\Http\Controllers;

use App\Helpers\Tools;
use App\Models\Works;
use App\Http\Resources\WorksConllection;

class WorksController extends ApiController
{
    /**
     * 获取作品列表
     *
     * @param   int $userId 分享的用户id
     *
     * @return $response;
     *
     * @author long
     */
    public function Works()
    {
        $userId = request('userId');
        $page = request('page');
        $userWorks = Works::User($userId)->first();

        $works = Works::NoUser([$userId])->orderBy('support_count', 'DESC')->paginate(12);



        if($page == 1 && $userWorks) {
            $works->prepend($userWorks);
        }


        $response = new WorksConllection($works);

        return $response;
    }
}
